
//导入 创建的方法 暴露router实例对象
import { createRouter, createWebHashHistory } from 'vue-router'
// 配置routerr实例对象
const routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        component: () => import('@/views/login/Login.vue')
    },
    {
        path: '/register',
        component: () => import('@/views/register/Register.vue'),

    },
    // home
    {
        path: '/layout',
        component: () => import('@/views/layout/Layout.vue'),

        redirect: '/home',
        children: [
            {
                path: '/home',
                component: () => import('@/views/home/Home.vue')
            },
            {
                path: '/acounterList',
                component: () => import('@/views/user/AcounterList.vue')
            },
            {
                path: '/updatePassword',
                component: () => import('@/views/user/UpdatePassword.vue')
            }
            , {
                path: '/orderList',
                component: () => import('@/views/order/OrderList.vue')
            },
            {
                path: '/TrainList',
                component: () => import('@/views/vehiclescheduling/TrainList.vue')
            },
            {
                path: '/trainTravelPlan',
                component: () => import('@/views/vehiclescheduling/TrainTravelPlan.vue')
            },

            {
                path: '/stationInfo',
                component: () => import('@/views/vehiclescheduling/StationInfo.vue')
            },

            {
                path: '/logdetail',
                component: () => import('@/views/log/LogDetail.vue')
            },
        ]
    },
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})


// 添加全局前置守卫  
router.beforeEach((to, from, next) => {
    // 如果路由的路径是'/' 或者是未定义的路径，则重定向到'/login'  
    if (to.path === '/') {
        next('/home');
    } else {
        next(); // 继续路由  
    }
});
// 暴露
export default router;


